//
//  UserService.m
//  OTOClient
//
//  Created by Suny on 15/4/16.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "UserService.h"

@implementation UserService
- (void)registerUser:(UserInfo *)user WithFinishBlock:(RequestFinishBlock)finishBlock;
{
	NSDictionary *dictionary = [user dictionaryWithNameAndValue];
	
	
	WEAKSELF;		
	AFHTTPRequestOperation * requestOperation = [self beginRequestWithRelativePath:kRegisterUrl
																	  parameterObject:dictionary
																		responseClass:nil
																		  finishBlock:^(BaseResponse *response) {
																			  [weakSelf removeWrapperForKey:kRegisterUrl];
																			  finishBlock(response);

																		  }];
	
	
	
	
	[self setWrapper:requestOperation
			  ForKey:kRegisterUrl];
}

- (void)loginUser:(UserInfo *)user WithFinishBlock:(RequestFinishBlock)finishBlock
{
	
	NSDictionary *dictionary = [user dictionaryWithNameAndValue];
	
	
	WEAKSELF;		
	AFHTTPRequestOperation * requestOperation = [self beginRequestWithRelativePath:kLoginUrl
																	  parameterObject:dictionary
																		responseClass:nil
																		  finishBlock:^(BaseResponse *response) {
																			  [weakSelf removeWrapperForKey:kLoginUrl];
																			  finishBlock(response);
																			  
																		  }];
	
	
	
	
	[self setWrapper:requestOperation
			  ForKey:kLoginUrl];
	
}


- (void)queryUserInfo:(UserInfo *)user withFinishBlock:(RequestFinishBlock)finishBlock
{	

	WEAKSELF;		
	AFHTTPRequestOperation * requestOperation = [self beginRequestWithRelativePath:[NSString stringWithFormat:@"%@/%@",kQueryUserInfoUrl,user.userId]
																	  parameterObject:nil
																		responseClass:nil
																		  finishBlock:^(BaseResponse *response) {
																			  if (response.success)
																			  {
																				  [user resetAllVarsByContent:response.object];
																				  
																				  response.object = user;
																			  }
																			  [weakSelf removeWrapperForKey:kQueryUserInfoUrl];
																			  finishBlock(response);
																			  
																		  }];
	
	
	
	
	[self setWrapper:requestOperation
			  ForKey:kQueryUserInfoUrl];
	
}

- (void)modifyUserInfo:(UserInfo *)user withFinishBlock:(RequestFinishBlock)finishBlock
{
	NSDictionary *dictionary = [user dictionaryWithNameAndValue];

	WEAKSELF;		
	AFHTTPRequestOperation * requestOperation = [self beginRequestWithRelativePath:[NSString stringWithFormat:@"%@/%@",kModifyUserInfoUrl,user.userId]
																	  parameterObject:dictionary
																		responseClass:nil
																		  finishBlock:^(BaseResponse *response) {
																			  [weakSelf removeWrapperForKey:kModifyUserInfoUrl];
																			  finishBlock(response);
																			  
																		  }];
	
	
	
	
	[self setWrapper:requestOperation
			  ForKey:kModifyUserInfoUrl];
	
}

- (void)modifyPassword:(UserInfo *)user 
		   newPassword:(NSString *)string
	   withFinishBlock:(RequestFinishBlock)finishBlock
{
	NSDictionary *dictionary = @{@"OriginalPassword":user.password,
								 @"newPassword":string,
								 @"memberId":user.userId};
	
	WEAKSELF;		
	AFHTTPRequestOperation * requestOperation = [self beginRequestWithRelativePath:kModifyPasswordUrl
																	  parameterObject:dictionary
																		responseClass:nil
																		  finishBlock:^(BaseResponse *response) {
																			  [weakSelf removeWrapperForKey:kModifyPasswordUrl];
																			  finishBlock(response);
																			  
																		  }];
	[self setWrapper:requestOperation
			  ForKey:kModifyPasswordUrl];
	
}

- (void)findPassword:(UserInfo *)user withFinishBlock:(RequestFinishBlock)finishBlock
{
	
}

@end
